package com.chuanyang.driverh.mainhome;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;

import com.chuanyang.driverh.R;
import com.chuanyang.driverh.base.BaseTitleActivity;
import com.chuanyang.driverh.mainhome.fragment.DriverApply2Fragment;
import com.chuanyang.driverh.mainhome.fragment.DriverJoinApplyFragment;
import com.chuanyang.driverh.mainhome.fragment.DriverJoinFragment;

public class DriverJoinApplyActivity extends BaseTitleActivity {

    private LinearLayout ll_container;
    private RadioGroup rg_top;
    private ImageView iv_search_back;

    private DriverJoinApplyFragment driverJoinApplyFragment;
    private DriverApply2Fragment driverApply2Fragment;

    private RelativeLayout rl_search;

    @Override
    protected int getContentResId() {
        return R.layout.activity_driver_join_apply;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        hideTitleBar();
        iv_search_back = (ImageView) findViewById(R.id.iv_search_back);
        ll_container = (LinearLayout) findViewById(R.id.ll_container);
        rg_top = (RadioGroup) findViewById(R.id.rg_top);
        rl_search = (RelativeLayout) findViewById(R.id.rl_search);
        rl_search.setOnClickListener(this);

        if (driverJoinApplyFragment == null) {
            driverJoinApplyFragment = new DriverJoinApplyFragment();
        }
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.ll_container, driverJoinApplyFragment).commit();
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initListener() {
        iv_search_back.setOnClickListener(this);
        rg_top.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId){
                    case R.id.rb_top1:
                        if (driverJoinApplyFragment == null) {
                            driverJoinApplyFragment = new DriverJoinApplyFragment();
                        }
                        getSupportFragmentManager().beginTransaction()
                                .replace(R.id.ll_container, driverJoinApplyFragment).commit();
                        break;
                    case R.id.rb_top2:
                        if (driverApply2Fragment == null) {
                            driverApply2Fragment = new DriverApply2Fragment();
                        }
                        getSupportFragmentManager().beginTransaction()
                                .replace(R.id.ll_container, driverApply2Fragment).commit();
                        break;
                }
            }
        });
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()){
            case  R.id.iv_search_back:
                finish();
                break;
            case R.id.rl_search:
                Intent intent = new Intent(DriverJoinApplyActivity.this,SearchJiaMengActivity.class);
                if(getIntent().getStringExtra("fleet") != null){
                    intent.putExtra("fleet",getIntent().getStringExtra("fleet"));
                }
                startActivity(intent);
                break;
        }
    }

}
